package com.ktjy.ktmall.controller;

import com.ktjy.common.annotation.Log;
import com.ktjy.common.core.controller.BaseController;
import com.ktjy.common.core.domain.AjaxResult;
import com.ktjy.common.core.page.TableDataInfo;
import com.ktjy.common.enums.BusinessType;
import com.ktjy.common.utils.poi.ExcelUtil;
import com.ktjy.ktmall.domain.SkuInfo;
import com.ktjy.ktmall.service.ISkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * skuController
 *
 * @author ktjy
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/ktmall/skuinfo")
public class SkuInfoController extends BaseController
{
    @Autowired
    private ISkuInfoService skuInfoService;

/**
 * 查询sku列表
 */
@PreAuthorize("@ss.hasPermi('ktmall:skuinfo:list')")
@GetMapping("/list")
    public TableDataInfo list(SkuInfo skuInfo)
    {
        startPage();
        List<SkuInfo> list = skuInfoService.selectSkuInfoList(skuInfo);
        return getDataTable(list);
    }


    /**
     * 导出sku列表
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuinfo:export')")
    @Log(title = "sku", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuInfo skuInfo)
    {
        List<SkuInfo> list = skuInfoService.list();
        ExcelUtil<SkuInfo> util = new ExcelUtil<SkuInfo>(SkuInfo.class);
        util.exportExcel(response, list, "sku数据");
    }

    /**
     * 获取sku详细信息
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(skuInfoService.getById(id));
    }

    /**
     * 新增sku
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuinfo:add')")
    @Log(title = "sku", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuInfo skuInfo)
    {
        return toAjax(skuInfoService.save(skuInfo));
    }

    /**
     * 修改sku
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuinfo:edit')")
    @Log(title = "sku", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuInfo skuInfo)
    {
        return toAjax(skuInfoService.updateById(skuInfo));
    }

    /**
     * 删除sku
     */
    @PreAuthorize("@ss.hasPermi('ktmall:skuinfo:remove')")
    @Log(title = "sku", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Integer> ids)
    {
        return toAjax(skuInfoService.removeByIds(ids));
    }
}